# -*- coding: utf-8 -*-
from venv1.Page.policyIfmComPage import policyIfmComPage
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from venv1.Public.dbClection import dbClection
import xlrd
from xlutils.copy import copy
import xlwt
class UWfllowup():
    def __init__(self,driver):
        self.driver=driver
        self.policyIfmComPage=policyIfmComPage(self.driver)
    def UW_fllowup(self,PolicyNo):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        self.policyIfmComPage.btnUWfllowup().click()
        time.sleep(1)
        self.policyIfmComPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        self.policyIfmComPage.btnPolicyGet().click()
        time.sleep(1)
        # 切換窗口
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        # 點擊彈框確認按鈕
        self.policyIfmComPage.btnSubmit().click()
        time.sleep(1)
        try:
            # 切換窗口
            window2 = self.driver.window_handles
            self.driver.switch_to.window(window2[-1])
            time.sleep(1)
            # 選擇目標數據
            self.policyIfmComPage.TargetData().click()
            time.sleep(2)
            window3 = self.driver.window_handles
            self.driver.switch_to.window(window3[-1])
            time.sleep(1)

            ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('W').perform()
            time.sleep(1)
            # window4 = self.driver.window_handles
            # self.driver.switch_to.window(window4[-1])
            # time.sleep(1)
            self.policyIfmComPage.btninsured().click()
            time.sleep(1)
            # 切換窗口
            # window5 = self.driver.window_handles
            # self.driver.switch_to.window(window5[-1])
            # time.sleep(1)
            # 點擊彈框確認按鈕
            self.policyIfmComPage.btnSubmit1().click()
            time.sleep(1)
            self.policyIfmComPage.btnSubmit().click()
            time.sleep(1)





        except Exception as msg:
            print('error:',msg)
    def lifeasia(self):
        db = dbClection()
        xzjd_org = db.getOrgid()
        print(xzjd_org)
        # 保单号
        a = xzjd_org[0]
        print(a)
        # # 电子合同
        # b=xzjd_org[1]
        # # 是否生效
        # c=xzjd_org[2]
        policyno = a['REFNO']
        econtract = a['LETTYPE']
        effective = a['STATCODE']

        print(policyno, econtract, effective)
        if effective == 'IF':
            effective1 = '有效'
        elif effective == 'DC':
            effective1 = '拒保'
        else:
            effective1 = '其他'

        if econtract == 'ZLPOLPAC':
            econtract1 = '生成'
        else:
            econtract1 = '不生成'
        excelpath = r'C:\Users\tanjm.ext\PycharmProjects\OWB\TestData\Data.xls'
        wtbook = xlrd.open_workbook(excelpath)
        newb = copy(wtbook)
        # sheet = newb.add_sheet('Sheet3')
        sheet = newb.get_sheet(1)
        row = 3
        sheet.write(row, 0, policyno)
        sheet.write(row, 3, effective1)
        sheet.write(row, 4, econtract1)
        row = row + 1

        newb.save(excelpath)







